function IsMobile(){
	const ua = navigator.userAgent || navigator.vendor || window.opera;
	return /android|iPhone|iPad|iPod|blackerry|iemobilemini/i.test(ua);
} 
function GetClientSize(){
	var clientWidth = document.documentElement.clientWidth;
	var clientHeight = document.documentElement.clientHeight;
	return {"width":clientWidth,"height":clientHeight};
}
function GetClientRect(id){
    var outerObj = document.getElementById(id);
    if(!outerObj){return null;}
    const rect = outerObj.getBoundingClientRect();
    return rect;
}
function strstr(targetString,find){
    if(typeof targetString!='string' || typeof find != 'string'){return -1;}
    return targetString.indexOf(find);
}
function strhas(trgetString,find){
    return strstr(trgetString,find)!=-1;
}
function Is09(s){ 
    let reg=/^[0-9]+$/;
    return reg.test(s);
}
function zIs09(s){ 
    let reg=/^[0-9]+$/;
    return reg.test(s);
}

/*
 format:"232323","-232","+2323"
*/
function zIsInt(s){
	if(!s){return false;}
	var res=true;
	var i=0;
	for(let c of s){
		if(!zIs09(c)){
			if(i==0){
				if(c!='-' && c!='+'){
					res=false;
					break;
				}
			}else{
				res=false;
				break;
			}
		}
		i++;
	}
	return res;
}
function zIsNumber(s){
	if(!s){return false;}
	var res=true;
	var i=0;
	var dotSum=0;
	for(let c of s){
		if(c=='.'){
			dotSum++;
		}
		else if(!zIs09(c)){
			if(i==0){
				if(c!='-' && c!='+'){
					res=false;
					break;
				}
			}else{
				res=false;
				break;
			}
		}
		i++;
	}
	return res && dotSum <= 1;
}

function zGetBrowserUrlParams(){
	var url=window.location.href;
	var pos = url.indexOf("?");
	if(pos<=0){return null;}
	var s2 = url.substr(pos+1);
	if(!s2){return null;}
	var ls=zSplit(s2,"&");
	var json=[];
	for(let x of ls){
		var ab = zSplit(x,"=");
		if(ab.length==2){
			var v = ab[1];
			if(zIsInt(ab[1])){
				v=parseInt(v);
			}else if(zIsNumber(ab[1])){
				v=parseFloat(v);
			}
			json[ab[0]] = v;
		}
	}
	return json;
}
function ExtractIntFromString(s,defval){
	if(!defval){defval=0;}
	if(typeof s != 'string'){return defval;}
	var n=s.length;
	var flag=false;
	var res='';
	for(var i=0;i<n;i++){
		if(Is09(s[i])){
			flag=true;
			res+=s[i];
		}else if(flag){
			break;
		}
	}
	if(res.length<1){return defval;}
	return  parseInt(res);
}
function __CopyInputText(ctrlid) {
    var obj=document.getElementById(ctrlid);
    if(!obj) return false;
	console.log("Select");
	var s = $("#_cttc0202");
	console.log(s.val());
	console.log(obj);

    obj.select();
    var r=document.execCommand("copy");
	console.log("Copy State:",r);

    return true;
}
function CopyTextToClipboard(s){
	var xml=`<input id="_cttc0202" type='text' value="${s}" style='width:2px;height:2px;position:fixed;top:0;top:-20px;'/>`;
	$("body").append(xml);
	$("#_cttc0202").val(s);
	__CopyInputText('_cttc0202');
	$("#_cttc0202").remove();
}

/* Firefox
Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1
*/
/* Chrome
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
*/
function IsChromeBrowser(){
	var flag = false;
	try{
		var agent = navigator.userAgent;
		//console.log(agent);
		if(agent.indexOf("Chrome")>0){
			flag = true;
		}
	}catch{}
	return flag;
}
function zParseJson(str){
	var res = null;
	try{
		res = JSON.parse(str);
	}catch{
	}
	return res;
}
function zGetUrlFilename(){
	var url =window.location.href;
	if(!url){return null;}
	var pos = url.lastIndexOf("/");
	if(-1 == pos){return null;}
	var dot = url.indexOf(".", pos);
	var filename = url.substring(pos+1, dot);
	filename = decodeURI(filename);
	return filename;
} 
function zSplit(s,sep){
    var ar=null;
    if(sep==' '){
        ar=s.split(/[ ,\n]/);
    }else{
        ar=s.split(sep);
    }
    var res=new Array();
    for(let c of ar){
        if(c.length>0){
            res.push(c);
        }
    }
    return res;
}
/* 范围浮点数FLOAT随机数，包含最小值/最大值本身 */
function zRandomRangeF(minval,maxval){
	maxval+=1;
	return Math.random() * (maxval-minval)+minval;
}
/* 范围整形INT随机数，包含最小值/最大值本身 */
function zRandomRangeI(minval,maxval){
	maxval+=1;
	var n = Math.random() * (maxval-minval)+minval;
	return parseInt(n);
}
function zHexToRGB(hex){
	if(hex[0]=='#'){
		hex = hex.substring(1);
	}
	//console.log(hex);
	var s1='',s2='',s3='';
	if(hex.length==3){
		s1=hex[0];
		s1+=hex[0];
		s2=hex[1];
		s2+=hex[1];
		s3=hex[2];
		s3+=hex[2];
	}else if(hex.length==6){
		s1=hex[0];
		s1+=hex[1];
		s2=hex[2];
		s2+=hex[3];
		s3=hex[4];
		s3+=hex[5];
	}
	var r = parseInt(s1,16);
	var g = parseInt(s2,16);
	var b = parseInt(s3,16);
	return {red:r, green:g, blue:b};
}
function zMaxColorChannel(hexcolor){
	var x = zHexToRGB(hexcolor);
	var v = x.red;
	if(x.green > v){v = x.green;}
	if(x.blue > v){v = x.blue;}
	return v;
}
function CUICStorage(){ 
	this.setBool=function(name,v){
		if(!name){return false;}
		localStorage.setItem(name,v?'1':'0');
		return true;
	}
	this.setInt=function(name,v){
		if(!name){return false;}
		localStorage.setItem(name,''+v);
		return true;
	}
	this.setNumber=function(name,v){
		if(!name){return false;}
		localStorage.setItem(name,''+v);
		return true;
	}
	this.getNumber=function(name,defval){
		if(!defval){defval=0;}
		var s = localStorage.getItem(name);
		if(s){
			return parseFloat(s);
		}
		return defval;
	} 
	this.getInt=function(name,defval){
		if(!defval){defval=0;}
		var s = localStorage.getItem(name);
		if(s){
			return parseInt(s);
		}
		return defval;
	} 
	this.getBool=function(name){
		if(!name){return false;}
		var s = localStorage.getItem(name);
		if(s=='1'){return true;}
		return false;
	} 
	this.setString=function(name,v){
		if(!name){return null;}
		localStorage.setItem(name, v);
		return true;
	} 
	this.getString=function(name){
		if(!name){return null;}
		var s = localStorage.getItem(name);
		return s;
	}
	this.removeItem=function(name){
		localStorage.removeItem(name);
	}
}
var STORAGE = new CUICStorage();